package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LXW
 * Date: 2022-03-22
 * Time: 12:33
 */
public class Demo9 {
    public static boolean flag = false;

    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while(!flag) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        });
        t.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        flag = true;
        System.out.println("终止线程");
    }

}
